package com.iflytek.topN;

import com.iflytek.top1.BestBean;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class BestTopNMapper extends Mapper<LongWritable, Text, BestBean,LongWritable> {

    BestBean outKey = new BestBean();
    LongWritable outValue = new LongWritable();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] fields = value.toString().split(",");

        outKey.set(fields[2],fields[1],Long.parseLong(fields[fields.length-2]));
        outValue.set(Long.parseLong(fields[fields.length-2]));

        context.write(outKey,outValue);
    }
}